#ifndef __MORPHTREE_H__
#define __MORPHTREE_H__

#include "../src/morphtree_impl.h"
#include "../src/node.h"

#include "util.h"

namespace morphtree {

class Morphtree {
private:
    MorphtreeImpl<NodeType::ROLEAF, false> *mt_; // NOTE: We use ROLeaf in DNSKV for simplicity

public:
    Morphtree() {
        // build from scratch
        mt_ = new MorphtreeImpl<NodeType::ROLEAF, false>();
    }

    ~Morphtree() {
        delete mt_;
    }

    inline void insert(_key_t key, uint64_t val) {
        mt_->insert(key, val);
    }

    inline bool update(_key_t key, uint64_t val) {
        return mt_->update(key, val);
    }

    inline uint64_t lookup(_key_t key) {
        uint64_t val;
        bool found = mt_->lookup(key, val);

        if (found) 
            return val;
        else 
            return 0;
    }

    inline uint64_t remove(_key_t key) {
        return mt_->remove(key);
    }

    inline int scan(_key_t startKey, _key_t endKey, std::vector<Record> & out) {
        return mt_->scan(startKey, endKey, out);
    }

    inline void print() {
        mt_->Print();
    }
};

} // morphtree

#endif //__MORPHTREE_H__